;

var user_edit_ops = {
    init: function () {
        this.eventBind();
    },
    eventBind: function () {
        $('#save').click(function () {
            var btn_target = $(this);

            if (btn_target.hasClass('disabled')) {
                common_ops.alert('正在处理，请不要重复提交!');
                return;
            }
            var old_password_target = $('#old_password');
            var new_password_target = $('#new_password');
            var old_password = old_password_target.val();
            var new_password = new_password_target.val();
            if (!old_password || old_password.length < 6 || old_password.length > 20) {
                common_ops.tip('请输入6-20位之间的字符', old_password_target);
                return;
            }
            if (!new_password || new_password.length < 6 || new_password.length > 20) {
                common_ops.tip('请输入6-20位之间的字符', new_password_target);
                return;
            }
            if (old_password !== new_password) {
                common_ops.tip('两次输入的密码不一致', new_password_target);
                return;
            }
            btn_target.addClass('disabled');

            $.ajax({
                url: '/user/resetpwd',
                data: {
                    'old_password': old_password,
                    'new_password': new_password
                },
                type: 'POST',
                dataType: 'json',
                success: function (data) {
                    btn_target.removeClass('disabled');
                    if (data['code'] == 200) {
                        var callback = function () {
                            window.location.href = common_ops.buildUrl('/');
                        };
                        common_ops.alert('个人信息修改成功！', callback);
                    }
                    else {
                        common_ops.alert(data['msg']);
                    }
                },
                fail: function () {
                    btn_target.removeClass('disabled');
                    common_ops.alert('数据提交失败，请重试！');
                }
            });
        });
    }
};

$(function () {
    user_edit_ops.init();
});